package gov.ccswj.modules.ccbusiness.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.quartz.Scheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import gov.ccswj.common.utils.PageUtils;
import gov.ccswj.common.utils.Query;
import gov.ccswj.common.utils.R;
import gov.ccswj.common.utils.SpringContextUtils;
import gov.ccswj.modules.ccbusiness.entity.CEntChronicleInfoEntity;
import gov.ccswj.modules.ccbusiness.entity.CHolderEntity;
import gov.ccswj.modules.ccbusiness.entity.CRegisterinfoEntity;
import gov.ccswj.modules.ccbusiness.service.CEntChronicleInfoService;
import gov.ccswj.modules.ccbusiness.service.CHolderService;
import gov.ccswj.modules.ccbusiness.service.CRegisterinfoService;
import gov.ccswj.modules.job.service.ScheduleJobService;
import gov.ccswj.modules.job.task.BeperformedinfoTask;
import gov.ccswj.modules.job.task.BiddinginfoTask;
import gov.ccswj.modules.job.task.BranchinfoTask;
import gov.ccswj.modules.job.task.ChangeinfoTask;
import gov.ccswj.modules.job.task.ChattelMortgageTask;
import gov.ccswj.modules.job.task.CourtannouncementTask;
import gov.ccswj.modules.job.task.EntAnnReportAssetsInfoTask;
import gov.ccswj.modules.job.task.EntAnnReportForGuaranteeInfoTask;
import gov.ccswj.modules.job.task.EntAnnReportInfoTask;
import gov.ccswj.modules.job.task.EntAnnReportInvInfoTask;
import gov.ccswj.modules.job.task.EntAnnReportWebSiteInfoTask;
import gov.ccswj.modules.job.task.EntChronicleInfoTask;
import gov.ccswj.modules.job.task.EntHonorTask;
import gov.ccswj.modules.job.task.ExecuteJudgmentInfoTask;
import gov.ccswj.modules.job.task.GeoPositionInfoTask;
import gov.ccswj.modules.job.task.HistoryInvestmentAbroadInfoTask;
import gov.ccswj.modules.job.task.HistoryShareHolderInfoTask;
import gov.ccswj.modules.job.task.HolderInfoTask;
import gov.ccswj.modules.job.task.ICPprecordinfoTask;
import gov.ccswj.modules.job.task.InternetShopInfoTask;
import gov.ccswj.modules.job.task.InvestmentAbroadInfoTask;
import gov.ccswj.modules.job.task.LawadmininfoTask;
import gov.ccswj.modules.job.task.LlostcreditinfoTask;
import gov.ccswj.modules.job.task.MainstaffTask;
import gov.ccswj.modules.job.task.OperatingExceptionRotaTask;
import gov.ccswj.modules.job.task.PatentinfoTask;
import gov.ccswj.modules.job.task.QualificationinfoTask;
import gov.ccswj.modules.job.task.RecruitmentinfoTask;
import gov.ccswj.modules.job.task.RegisterinfoTask;
import gov.ccswj.modules.job.task.RiskassessmentTask;
import gov.ccswj.modules.job.task.SoftwarecopyrightTask;
import gov.ccswj.modules.job.task.TrademarkinfoTask;
import gov.ccswj.modules.job.task.WorkscopyrightTask;




/**
 * 
 * 
 * @author ZhangYx
 * @email ********@gmail.com
 * @date 2017-10-31 11:46:25
 */
@RestController
@RequestMapping("/ccbusiness/cregisterinfo")
public class CRegisterinfoController {
	@Autowired
	private CRegisterinfoService cRegisterinfoService;
	@Autowired
    private Scheduler scheduler;
	@Autowired
	private ScheduleJobService schedulerJobService;
    private static Logger log = LoggerFactory.getLogger(CRegisterinfoController.class);
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("ccbusiness:cregisterinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		if (params.get("regcap")!=null) {
			String regcap = params.get("regcap").toString();
			if (regcap.equals("1")) {
				params.put("regcap1", "0");
				params.put("regcap2", "100");
			} else if (regcap.equals("2")) {
				params.put("regcap1", "100");
				params.put("regcap2", "1000");
			} else if (regcap.equals("3")) {
				params.put("regcap1", "1000");
			}
			params.remove("regcap");
		}
		
		String searchname=params.get("entname").toString();
		try {
			if(searchname!=null && searchname.length()!=0){
				RegisterinfoTask registerinfoTask = (RegisterinfoTask) SpringContextUtils.getBean("RegisterInfoTask");
				registerinfoTask.runner(searchname);
				Thread thread= new Threadcompany(searchname);
				thread.start();
			}
		} catch (Exception e) {
			log.error("龙信接口获取失败", e);
		}
		
		//查询列表数据
        Query query = new Query(params);
        
		List<CRegisterinfoEntity> cRegisterinfoList = cRegisterinfoService.queryList(query);
		int total = cRegisterinfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(cRegisterinfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 投资项目推荐列表
	 */
	@RequestMapping("/listcompany")
	@RequiresPermissions("ccbusiness:cregisterinfo:list")
	public R listcompany(@RequestParam Map<String, Object> params){
		if (params.get("regcap")!=null) {
			String regcap = params.get("regcap").toString();
			if (regcap.equals("1")) {
				params.put("regcap1", "0");
				params.put("regcap2", "100");
			} else if (regcap.equals("2")) {
				params.put("regcap1", "100");
				params.put("regcap2", "1000");
			} else if (regcap.equals("3")) {
				params.put("regcap1", "1000");
			}
			params.remove("regcap");
		}
		
		String searchname=params.get("entname").toString();
		try {
			if(searchname!=null && searchname.length()!=0){
				RegisterinfoTask registerinfoTask = (RegisterinfoTask) SpringContextUtils.getBean("RegisterInfoTask");
				registerinfoTask.runner(searchname);
				Thread thread= new Threadcompany(searchname);
				thread.start();
			}
		} catch (Exception e) {
			log.error("龙信接口获取失败", e);
		}
		
		//查询列表数据
        Query query = new Query(params);
        
		List<CRegisterinfoEntity> cRegisterinfoList = cRegisterinfoService.listcompany(query);
		int total = cRegisterinfoService.queryTotalcompany(query);
		
		PageUtils pageUtil = new PageUtils(cRegisterinfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	
	

	@Autowired
	private CHolderService cHolderService;
	@Autowired
	private CEntChronicleInfoService cEntChronicleInfoService;
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("ccbusiness:cregisterinfo:info")
	public R info(@PathVariable("id") Integer id){
		CRegisterinfoEntity cRegisterinfo = cRegisterinfoService.queryObject(id);
		List<CHolderEntity> holderList = cHolderService.queryListByEntname(cRegisterinfo.getEntname());
		List<CEntChronicleInfoEntity> entChronicleInfoList = cEntChronicleInfoService.queryListByEntname(cRegisterinfo.getEntname());
		
		return R.ok().put("cRegisterinfo", cRegisterinfo).put("holderList", holderList).put("entChronicleInfoList", entChronicleInfoList);
	}
	/**
	 * 信息
	 */
	@RequestMapping("/infobyname/{entname}")
	public R infobyname(@PathVariable("entname") String entname){
		CRegisterinfoEntity cRegisterinfo = cRegisterinfoService.queryObjectByName(entname);
		List<CHolderEntity> holderList = cHolderService.queryListByEntname(cRegisterinfo.getEntname());
		List<CEntChronicleInfoEntity> entChronicleInfoList = cEntChronicleInfoService.queryListByEntname(cRegisterinfo.getEntname());
		
		return R.ok().put("cRegisterinfo", cRegisterinfo).put("holderList", holderList).put("entChronicleInfoList", entChronicleInfoList);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("ccbusiness:cregisterinfo:save")
	public R save(@RequestBody CRegisterinfoEntity cRegisterinfo){
		cRegisterinfoService.save(cRegisterinfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("ccbusiness:cregisterinfo:update")
	public R update(@RequestBody CRegisterinfoEntity cRegisterinfo){
		cRegisterinfoService.update(cRegisterinfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("ccbusiness:cregisterinfo:delete")
	public R delete(@RequestBody Integer[] ids){
		cRegisterinfoService.deleteBatch(ids);
		
		return R.ok();
	}
	
	private class Threadcompany extends Thread{
		public Threadcompany(String cname){
			super (cname);
		}
		public void run(){
			HolderInfoTask HolderInfoTask = (HolderInfoTask) SpringContextUtils.getBean("HolderInfoTask");
			HolderInfoTask.runner(this.getName());
			
			InvestmentAbroadInfoTask InvestmentAbroadInfoTask = (InvestmentAbroadInfoTask) SpringContextUtils.getBean("InvestmentAbroadInfoTask");
			InvestmentAbroadInfoTask.runner(this.getName());
			
			BranchinfoTask BranchinfoTask = (BranchinfoTask) SpringContextUtils.getBean("BranchinfoTask");
			BranchinfoTask.runner(this.getName());
			
			ChangeinfoTask ChangeinfoTask = (ChangeinfoTask) SpringContextUtils.getBean("ChangeinfoTask");
			ChangeinfoTask.runner(this.getName());
			
			PatentinfoTask PatentinfoTask = (PatentinfoTask) SpringContextUtils.getBean("PatentinfoTask");
			PatentinfoTask.runner(this.getName());
			
			ChattelMortgageTask ChattelMortgageTask = (ChattelMortgageTask) SpringContextUtils.getBean("ChattelMortgageTask");
			ChattelMortgageTask.runner(this.getName());
			
			BeperformedinfoTask BeperformedinfoTask = (BeperformedinfoTask) SpringContextUtils.getBean("BeperformedinfoTask");
			BeperformedinfoTask.runner(this.getName());
			
			BiddinginfoTask BiddinginfoTask = (BiddinginfoTask) SpringContextUtils.getBean("BiddinginfoTask");
			BiddinginfoTask.runner(this.getName());
			
			CourtannouncementTask CourtannouncementTask = (CourtannouncementTask) SpringContextUtils.getBean("CourtannouncementTask");
			CourtannouncementTask.runner(this.getName());
			
			EntHonorTask EntHonorTask = (EntHonorTask) SpringContextUtils.getBean("EntHonorTask");
			EntHonorTask.runner(this.getName());
			
			ICPprecordinfoTask ICPprecordinfoTask = (ICPprecordinfoTask) SpringContextUtils.getBean("ICPprecordinfoTask");
			ICPprecordinfoTask.runner(this.getName());
			
			LawadmininfoTask LawadmininfoTask = (LawadmininfoTask) SpringContextUtils.getBean("LawadmininfoTask");
			LawadmininfoTask.runner(this.getName());
			
			LlostcreditinfoTask LostcreditinfoTask = (LlostcreditinfoTask) SpringContextUtils.getBean("LostcreditinfoTask");
			LostcreditinfoTask.runner(this.getName());
			
			QualificationinfoTask QualificationinfoTask = (QualificationinfoTask) SpringContextUtils.getBean("QualificationinfoTask");
			QualificationinfoTask.runner(this.getName());
			
			RecruitmentinfoTask RecruitmentinfoTask = (RecruitmentinfoTask) SpringContextUtils.getBean("RecruitmentinfoTask");
			RecruitmentinfoTask.runner(this.getName());
			
			SoftwarecopyrightTask SoftwarecopyrightTask = (SoftwarecopyrightTask) SpringContextUtils.getBean("SoftwarecopyrightTask");
			SoftwarecopyrightTask.runner(this.getName());
			
			TrademarkinfoTask TrademarkinfoTask = (TrademarkinfoTask) SpringContextUtils.getBean("TrademarkinfoTask");
			TrademarkinfoTask.runner(this.getName());
			
			WorkscopyrightTask WorkscopyrightTask = (WorkscopyrightTask) SpringContextUtils.getBean("WorkscopyrightTask");
			WorkscopyrightTask.runner(this.getName());
			
//			EquityPledgedTask EquityPledgedTask = (EquityPledgedTask) SpringContextUtils.getBean("EquityPledgedTask");
//			EquityPledgedTask.runner(this.getName());
			
			InternetShopInfoTask InternetShopInfoTask = (InternetShopInfoTask) SpringContextUtils.getBean("InternetShopInfoTask");
			InternetShopInfoTask.runner(this.getName());
			
			ExecuteJudgmentInfoTask ExecuteJudgmentInfoTask = (ExecuteJudgmentInfoTask) SpringContextUtils.getBean("ExecuteJudgmentInfoTask");
			ExecuteJudgmentInfoTask.runner(this.getName());
			
			EntChronicleInfoTask EntChronicleInfoTask = (EntChronicleInfoTask) SpringContextUtils.getBean("EntChronicleInfoTask");
			EntChronicleInfoTask.runner(this.getName());
			
			RiskassessmentTask RiskassessmentTask = (RiskassessmentTask) SpringContextUtils.getBean("RiskassessmentTask");
			RiskassessmentTask.runner(this.getName());
			
			EntAnnReportAssetsInfoTask EntAnnReportAssetsInfoTask = (EntAnnReportAssetsInfoTask) SpringContextUtils.getBean("EntAnnReportAssetsInfoTask");
			EntAnnReportAssetsInfoTask.runner(this.getName());
			
			EntAnnReportForGuaranteeInfoTask EntAnnReportForGuaranteeInfoTask = (EntAnnReportForGuaranteeInfoTask) SpringContextUtils.getBean("EntAnnReportForGuaranteeInfoTask");
			EntAnnReportForGuaranteeInfoTask.runner(this.getName());
			
			EntAnnReportInfoTask EntAnnReportInfoTask = (EntAnnReportInfoTask) SpringContextUtils.getBean("EntAnnReportInfoTask");
			EntAnnReportInfoTask.runner(this.getName());
			
			EntAnnReportInvInfoTask EntAnnReportInvInfoTask = (EntAnnReportInvInfoTask) SpringContextUtils.getBean("EntAnnReportInvInfoTask");
			EntAnnReportInvInfoTask.runner(this.getName());
			
			EntAnnReportWebSiteInfoTask EntAnnReportWebSiteInfoTask = (EntAnnReportWebSiteInfoTask) SpringContextUtils.getBean("EntAnnReportWebSiteInfoTask");
			EntAnnReportWebSiteInfoTask.runner(this.getName());
			
			GeoPositionInfoTask GeoPositionInfoTask = (GeoPositionInfoTask) SpringContextUtils.getBean("GeoPositionInfoTask");
			GeoPositionInfoTask.runner(this.getName());
			
			HistoryShareHolderInfoTask HistoryShareHolderInfoTask = (HistoryShareHolderInfoTask) SpringContextUtils.getBean("HistoryShareHolderInfoTask");
			HistoryShareHolderInfoTask.runner(this.getName());
			
			HistoryInvestmentAbroadInfoTask HistoryInvestmentAbroadInfoTask = (HistoryInvestmentAbroadInfoTask) SpringContextUtils.getBean("HistoryInvestmentAbroadInfoTask");
			HistoryInvestmentAbroadInfoTask.runner(this.getName());
			
			MainstaffTask MainstaffTask = (MainstaffTask) SpringContextUtils.getBean("MainstaffTask");
			MainstaffTask.runner(this.getName());
			
			OperatingExceptionRotaTask OperatingExceptionRotaTask = (OperatingExceptionRotaTask) SpringContextUtils.getBean("OperatingExceptionRotaTask");
			OperatingExceptionRotaTask.runner(this.getName());
		}
	}
	
}
